﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using DevExpress.Web.ASPxGridView;
using TrangTrai.Data.DAO;
using DevExpress.XtraCharts.Web;
using DevExpress.XtraCharts;

namespace Trangtrai.report
{
    public partial class report : System.Web.UI.Page
    {
        static SeasonInfo[] arrSeasons = null;
        static AoInfo[] arrAoInfo = null;
        GroupManagementDAO dao = new GroupManagementDAO();
        AoManageDAO aoDao = new AoManageDAO();
        ReportDAO reportDao = new ReportDAO();
        static ChoAnReport[] foodReport = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            
            if (!IsPostBack)
            {
                arrSeasons = dao.getSeasonList();
                arrAoInfo = dao.getActiveAoList();
                cbAoCode.DataSource = arrAoInfo;
                cbAoCode.DataBind();
                cbSeason.DataSource = arrSeasons;
                cbSeason.DataBind();
                grid.ExpandRow(0);
            }
            grid.DataSource = foodReport;
            grid.DataBind();
        }

        protected void grid_CustomUnboundColumnData(object sender, ASPxGridViewColumnDataEventArgs e)
        {
            if (e.Column.FieldName == "Total")
            {
                double actualValue = (double)e.GetListSourceFieldValue("actualValue");
                e.Value = actualValue ;
                
            }
        }

        protected void btnsearch_Click(object sender, EventArgs e)
        {
             
            int aoId = (int)cbAoCode.Value;
            int seasonId = (int)cbSeason.Value;
            DateTime _toDate = (DateTime)toDate.Value;
            foodReport = reportDao.getFoodReport(aoId, seasonId, _toDate);
             grid.DataSource = foodReport;
             grid.DataBind();
             bindDataToChart(wcFoodReport);
        }
        void bindDataToChart(WebChartControl wcControls) {
            Series actualSeries = (Series)wcControls.Series["actualValue"];
            Series standardSeries = (Series)wcControls.Series["standardValue"];
            Series sampleSeries = (Series)wcControls.Series["sampleValue"];
            foreach (ChoAnReport item in foodReport) {

                actualSeries.Points.Add(new SeriesPoint(item.tomAge, new double[] { (double)item.actualValue}));
                standardSeries.Points.Add(new SeriesPoint(item.tomAge, new double[] { (double)item.standardValue }));
                sampleSeries.Points.Add(new SeriesPoint(item.tomAge, new double[] { (double)item.samValue }));    
            }
            
             //wcControls.DataSource = foodReport;
            //wcControls.SeriesDataMember = "tomAge";
            //wcControls.SeriesTemplate.ArgumentDataMember = "actualValue";
            //wcControls.SeriesTemplate.ValueDataMembers.AddRange(new string[] { "actualValue", "standardValue", "samValue" });
            //wcControls.DataBind();

            
        }
    }
}
